<template>
  <div class="setmng-box">
    <div class="content-box w-card">
      <div class="title-box">
        <span>上游平台</span>
      </div>
      <div class="table-box">
        <el-table :height="tableHeight" :header-cell-style="{background:'#d6dee5',color:'#000000',fontSize:'14px'}"
          :cell-style="{fontSize:'14px',color:'#7b7b7d'}" :data="tableData" stripe>
          <el-table-column type="index" width="55" label="序号" align="center" />
          <el-table-column prop="operatorName" label="平台名称" align="center">
            <template v-slot="scope">
              {{ scope.row.operatorName || '' }}
            </template>
          </el-table-column>
          <!-- <el-table-column prop="operatorCode" label="平台标识" align="center">
            <template v-slot="scope">
              {{ scope.row.operatorCode || '' }}
            </template>
          </el-table-column> -->
          <el-table-column prop="chooseNumType" label="是否支持选号" align="center">
            <template v-slot="scope">
              <div>{{ scope.row.chooseNumType == 1 ? '支持' : scope.row.chooseNumType == 0 ? '不支持' : '' }}</div>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="price" label="对接价格(元)" align="center">
            <template v-slot="scope">
              {{ numFormat(scope.row.price/100) || '' }}
            </template>
          </el-table-column> -->
          <el-table-column prop="otherReqUrl" label="平台请求地址" align="center">
            <template v-slot="scope">
              {{ scope.row.otherReqUrl || '' }}
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="180">
            <template v-slot="scope">
              <el-link type="primary" @click="lookProd(scope.row)">查看产品</el-link>
            </template>
          </el-table-column>
        </el-table>
        <div class="table-footer">
          <div>
          </div>
          <el-pagination v-model:currentPage="page" v-model:page-size="size" :page-sizes="[10, 20, 50, 100]" small
            :background="true" layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
            @current-change="handleCurrentChange" />
        </div>
      </div>
    </div>
    <look-prod ref="lookProdRef" />
  </div>
</template>

<script>
import { onMounted, reactive, ref, toRefs } from 'vue'
import { warningDeal, getDateTime, getWindowWidthAndHeight, successDeal, numFormat } from '@/utils/utils'
import lookProd from './components/lookProd.vue'
import api from './api'
export default {
  components: {
    lookProd,
  },
  setup() {
    const lookProdRef = ref(null)

    const state = reactive({
      page: 1,
      size: 10,
      total: 0,
      tableHeight: 0,
      tableData: [],
    })

    function getTableData() {
      const obj = {
        page: state.page,
        size: state.size,
      }
      api.getTableData(obj).then(res => {
        if (res.code == '200') {
          state.tableData = res.data.list
          state.total = res.data.total
        } else {
          warningDeal(res.msg)
        }
      }).catch(err => {
        console.log(err)
      })
    }

    function handleSizeChange(e) {
      state.size = e
      getTableData()
    }

    function handleCurrentChange(e) {
      state.page = e
      getTableData()
    }

    function lookProd(data) {
      lookProdRef.value.dialogShow(data)
    }

    onMounted(() => {
      let winHeight = getWindowWidthAndHeight()
      state.tableHeight = winHeight.windowHeight - 230
      getTableData()
    })

    return {
      ...toRefs(state),
      lookProdRef,
      getDateTime,
      handleSizeChange,
      handleCurrentChange,
      lookProd,
      numFormat,
    }
  }
}
</script>

<style lang="scss" scoped>
.setmng-box {
  width: 100%;
  height: 100%;
  .content-box {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    padding: 20px;
    .title-box {
      display: flex;
      align-items: center;
      padding-bottom: 20px;
      > span {
        font-size: 16px;
        font-weight: bold;
      }
    }
    .table-box {
      .table-footer {
        margin-top: 20px;
        display: flex;
        justify-content: space-between;
      }
    }
  }
}
</style>